package org.mdrtwell.swing.jtable;

import java.awt.BorderLayout;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;

public class TableExample extends JPanel {
	/**
	 * 
	 */
	private JTable	table;

	public TableExample() {
		setLayout(new BorderLayout(0, 0));
		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane, BorderLayout.CENTER);
		// table = new JTable(new DefaultTableModel(10, 10) {
		// @Override
		// public Object getValueAt(int row, int column) {
		// Object val = super.getValueAt(row, column);
		// return "	row:" + row + "	column:" + column + "	val:" + val;
		// }
		// });
		table = new JTable(new AbstractTableModel() {

			@Override
			public Object getValueAt(int rowIndex, int columnIndex) {
				return rowIndex + "," + columnIndex;
			}

			@Override
			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return true;
			}

			@Override
			public int getRowCount() {
				return 100;
			}

			@Override
			public int getColumnCount() {
				return 5;
			}
		});
		table.setRowHeight(50);
		scrollPane.setViewportView(table);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				JDialog dialog = new JDialog();
				dialog.setContentPane(new TableExample());
				dialog.pack();
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				dialog.setVisible(true);
			}
		});
	}
}
